package com.wangzhen.shardingsphere.service.impl;

import com.alibaba.fastjson.JSON;
import com.wangzhen.shardingsphere.entity.User;
import com.wangzhen.shardingsphere.mapper.UserMapper;
import com.wangzhen.shardingsphere.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dell
 * @since 2021/7/6 10:32
 */
@Service
public class UserServiceImpl implements UserService
{

    @Autowired
    private UserMapper userMapper;

    private static Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Override
    public boolean insertUser(User user) {
        int insert = userMapper.insert(user);
        logger.info("插入会员信息， 会员信息：{}", JSON.toJSONString(user));
        return insert ==1 ? true : false;
    }

    @Override
    public List<User> findAll() {
        return null;
    }

    @Override
    public User findById(Integer userId) {
        User user = userMapper.selectByPrimaryKey(userId);
        logger.info("查询userId={}的会员信息是：{}", userId, JSON.toJSONString(user));
        return user;
    }
}
